package bb.lanxing.calc.data;

import android.location.Location;
import com.baidu.mapapi.model.LatLng;
import com.github.mikephil.charting.utils.Utils;

import bb.lanxing.model.database.Workout;

public class GpsPoint implements Cloneable, RecycleData {
    private float accuracy;
    private double altitude;
    private float bearing;
    private double latitude;
    private Location location;
    private double longitude;
    private int source;
    private float speed;
    private long timestamp;

    public GpsPoint() {
        this.latitude = 90.0d;
        this.longitude = 180.0d;
    }

    public GpsPoint(Location location) {
        this.latitude = 90.0d;
        this.longitude = 180.0d;
        this.location = location;
        this.latitude = location.getLatitude();
        this.longitude = location.getLongitude();
        this.altitude = location.getAltitude();
        this.accuracy = location.getAccuracy();
        this.speed = location.getSpeed();
        this.bearing = location.getBearing();
        this.timestamp = location.getTime();
        this.source = Workout.LOCATION_SOURCE_PHONE;
    }

    public GpsPoint copy(GpsPoint reuse) {
        if (reuse == null) {
            reuse = new GpsPoint();
        }
        reuse.location = this.location;
        reuse.latitude = this.latitude;
        reuse.longitude = this.longitude;
        reuse.altitude = this.altitude;
        reuse.accuracy = this.accuracy;
        reuse.speed = this.speed;
        reuse.bearing = this.bearing;
        reuse.timestamp = this.timestamp;
        reuse.source = this.source;
        return reuse;
    }

    public GpsPoint clone() {
        try {
            return (GpsPoint) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public void recycle() {
        this.location = null;
        this.latitude = 90.0d;
        this.longitude = 180.0d;
        this.altitude = Utils.DOUBLE_EPSILON;
        this.accuracy = 0.0f;
        this.speed = 0.0f;
        this.bearing = 0.0f;
        this.timestamp = 0L;
        this.source = Workout.LOCATION_SOURCE_NONE;
    }

    public LatLng getLatLng() {
        return new LatLng(this.latitude, this.longitude);
    }

    public Location getLocation() {
        return this.location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    public double getLatitude() {
        return this.latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return this.longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getAltitude() {
        return this.altitude;
    }

    public void setAltitude(double altitude) {
        this.altitude = altitude;
    }

    public float getAccuracy() {
        return this.accuracy;
    }

    public void setAccuracy(float accuracy) {
        this.accuracy = accuracy;
    }

    public float getSpeed() {
        return this.speed;
    }

    public void setSpeed(float speed) {
        this.speed = speed;
    }

    public float getBearing() {
        return this.bearing;
    }

    public void setBearing(float bearing) {
        this.bearing = bearing;
    }

    public long getTimestamp() {
        return this.timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public int getSource() {
        return this.source;
    }

    public void setSource(int source) {
        this.source = source;
    }
}
